import { createSlice } from '@reduxjs/toolkit';

const initialState = {
  isAuthenticated: JSON.parse(localStorage.getItem('isAuthenticated')) || false,

};

const authSlice = createSlice({
  name: 'auth',
  initialState,
  reducers: {
    setAuthState(state, action) {
      const { isAuthenticated,  } = action.payload;
      state.isAuthenticated = isAuthenticated;
      localStorage.setItem('isAuthenticated', true);

    },
    clearAuthState(state) {
      state.isAuthenticated = false;
      localStorage.removeItem('isAuthenticated');
      sessionStorage.removeItem('accessToken');
      },
  },
});

export const { setAuthState, clearAuthState } = authSlice.actions;

export default authSlice.reducer;
